#! /usr/bin/python
book = "alice_in_wonderland.txt"
list = dict()
from operator import itemgetter

def GetUniqueWords(text):
  text2 = text.replace(","," ").replace(","," ").replace("."," ").replace("!"," ").replace("?"," ").replace("*"," ").replace("-"," ").replace("--"," ").replace(":"," ").replace(";"," ").replace("//"," ").replace('"'," ").replace('*'," ").replace("("," ").replace(")"," ").lower().strip()
  for word in text2.split():
    if list.__contains__(word):
      list[word] += 1
    else:
      list[word] = 1
  return list.__len__()


def main():
  # Open the file, read it into memory as a single string.
  with open('alice_in_wonderland.txt') as alice_file:
    alice_text = alice_file.read()
  print 'Unique words:', GetUniqueWords(alice_text)

def lead(list):
  newlist = sorted(list, key=itemgetter(0)) 
  print "most used words"
  for i in range(10):
    n = i + 1
    print "%r: %r" % (n, newlist[i])
  print "the least used words"
  for x in range(10):
    z = 10 - x
    w = x + 1
    print "%r: %r" % (w, newlist[-w])
  #print newlist
  
#def hundred():
  

#sorted(foo.items(), key=lambda(k,v):(v,k))

if __name__ == '__main__':
  main()
  lead(list)
  #this was for testing only
  #print list
